<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE html>
<html lang="en">

<head>
	<base href="<%=basePath%>">
  	<!-- jsp文件头和头部 -->
  	<%@ include file="../../system/admin/top.jsp"%> 
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>新建处方单</title>
    <!--提示框-->
	<script type="text/javascript" src="static/js/jquery.tips.js"></script>
    <script type="text/javascript">
			$(top.hangge());
	</script>
	<style>
    	.table th,
    	.table td {
    		text-align:center;
    		vertical-align:middle;
    	}
    	form {
		    margin: 8px 10px 0;
		}
		.table {
			margin-left: 10px;
		}
    </style>    
</head>

<body>
    <div class="container-fluid">
        <div class="row">
	        <!-- 检索患者首个病历  -->
			<form action="cfOrder/findCaseOrder.do" method="post" name="userForm" id="userForm">
				<table>
					<tr>
						<td>
							<span class="input-icon">
								<input autocomplete="off" id="nav-search-input" type="text" name="name" value="${pd.name}" placeholder="这里输入姓名" />
								<i id="nav-search-icon" class="icon-search"></i>
							</span>
						</td>
						<td>
							<span class="input-icon">
								<input autocomplete="off" id="phone" type="text" name="phone" value="${pd.phone}" placeholder="这里输入电话" />
								<i id="nav-search-icon2" class="icon-search"></i>
							</span>
						</td>
						<td style="vertical-align:top;"><button class="btn btn-mini btn-light" onclick="find();" title="检索"><i id="nav-search-icon" class="icon-search"></i></button></td>
					</tr>
				</table>
			</form>
			<!-- 检索  -->
			
			<!-- 多条数据时，展示列表 -->
        	<c:if test="${has==2}">
				<div id="more">
					<table id="table_report" class="table table-striped table-bordered table-hover">
						<thead>
							<tr>
								<th class="center">
								<label><input type="checkbox" id="zcheckbox" /><span class="lbl"></span></label>
								</th>
								<th>序号</th>
								<th>姓名</th>
								<th>性别</th>
								<th>年龄</th>
								<th>电话</th>
								<th>现病史</th>
								<th>病历录入时间</th>
								<th class="center">操作</th>
							</tr>
						</thead>
						<tbody>
						<!-- 开始循环 -->	
							<c:forEach items="${caseOrderList}" var="caseOrder" varStatus="vs">
								<tr>
									<td class='center' style="width: 30px;">
										<label><input type='checkbox' disabled="disabled" /><span class="lbl"></span></label>
									</td>
									<td class='center' style="width: 30px;">${vs.index+1}</td>
									<td>${caseOrder.name }</td>
									<td>${caseOrder.sex }</td>
									<td>${caseOrder.age }</td>
									<td>${caseOrder.phone }</td>
									<td>${caseOrder.xbs }</td>
									<td>${caseOrder.updateDate }</td>
									<td style="width:100px;"><a class="btn btn-mini btn-success" href="<%=basePath%>cfOrder/findCaseOrder?id=${caseOrder.id}" >新建处方</a></td>
<%-- 								<td><a class="btn btn-success" onclick="toAdd('${caseOrder.hzId}','${caseOrder.id}','${caseOrder.name}','${caseOrder.sex}','${caseOrder.age}','${caseOrder.phone}','${caseOrder.xbs}','${caseOrder.zd}');" >新建处方</a></td> --%>
								</tr>
							</c:forEach>
						</tbody>
					</table>
					<div class="page-header position-relative">
						<table style="width:100%;">
							<tr>
								<td style="vertical-align:top;"><div class="pagination" style="float: right;padding-top: 0px;margin-top: 0px;">${page.pageStr}</div></td>
							</tr>
						</table>
					</div>	
				</div>
			</c:if>
			
        <%-- 
            <!-- 患者主要信息展示页面 -->
            <div class="col-sm-offset-2 col-sm-8 col-md-offset-2 col-md-8 col-lg-offset-2 col-lg-8  main">
                <form  id="cfCardForm">
                    <!-- 患者信息 -->
                    <div class="r1">
                        <div class="col-sm-2 col-md-2 col-lg-2 lf left ">
                            <i>*</i>
                            <span>姓名:</span>
                        </div>
                        <div class="col-sm-10 col-md-10 col-lg-10 lf right">
                            <!-- 姓名输入框 -->
                            <div class="col-sm-6 col-md-6 col-lg-6 box">
                                <input type="text" class="name" placeholder="请输入患者姓名" value="${caseOrder.name }" readonly="readonly">
                            </div>
                            <!-- 性别选择 -->
                            <div class="col-sm-6 col-md-6 col-lg-6 sex">
                                <div class="left lf">
                                    <i>*</i>
                                    <span>姓别:</span>
                                </div>
                                <div class="right">
                                    <label id="sex">${caseOrder.sex }</label>
                                </div>
                            </div>
                        </div>
                    </div>
                    <!-- 年龄及联系方式 -->
                    <div class="r2">
                        <div class="col-sm-2 col-md-2 col-lg-2 lf left ">
                            <i>*</i>
                            <span>年龄:</span>
                        </div>
                        <div class="col-sm-10 col-md-10 col-lg-10 lf right">
                            <!-- 年龄输入框 -->
                            <div class="col-sm-6 col-md-6 col-lg-6 box">
                                <input type="text" class="age" placeholder="请输入患者年龄" value="${caseOrder.age }" readonly="readonly">&nbsp;&nbsp; 岁
                            </div>
                            <!-- 联系方式 -->
                            <div class="col-sm-6 col-md-6 col-lg-6">
                                <div class="left lf">
                                    <i>*</i>
                                    <span>电话:</span>
                                </div>
                                <div class="right">
                                    <input type="text" class="phone" placeholder="请输入您的联系方式" value="${caseOrder.phone }" readonly="readonly">
                                </div>
                            </div>
                        </div>
                    </div>
                    <!-- 医生主诉 -->
                    <div class="r7">
                        <div class="col-sm-2 col-md-2 col-lg-2 lf left ">
                            <span>主诉/现病史:</span>
                        </div>
                        <div class="col-sm-10 col-md-10 col-lg-10 lf right">
                            <input type="text" class="yszs xbs" placeholder="请输入病人病史" value="${caseOrder.xbs }" readonly="readonly">
                        </div>
                    </div>
                    <!-- 医生诊断 -->
                    <div class="r7">
                        <div class="col-sm-2 col-md-2 col-lg-2 lf left ">
                            <i>*</i>
                            <span>诊断:</span>
                        </div>
                        <div class="col-sm-10 col-md-10 col-lg-10 lf right">
                            <input type="text" class="yszd zd" placeholder="请输入诊断结果" value="${caseOrder.zd }" readonly="readonly">
                        </div>
                    </div>
                    <!-- 处方 -->
                    <div class="cf">
                        <div class="col-sm-2 col-md-2 col-lg-2 lf left ">
                            <span>处方:</span>
                        </div>
                        <div class="col-sm-10 col-md-10 col-lg-10 lf right">
                           <!--  <div class="zrcf">
                                <a class="btn btn-info" data-toggle="modal" data-target="#ceshi" onclick="load();">载入常用处方</a>
                            </div> -->
                            <div class="table-responsive">
                                <table class="table table-bordered table-hover" id="table4">
                                    <tr>
                                        <td>序号</td>
                                        <td>编号</td>
                                        <td>名称</td>
                                        <td>单位</td>
                                        <td>用法</td>
                                        <td>单价</td>
                                        <td>用量</td>
                                        <td>总价</td>
                                    </tr>
                                </table>  
                                <div class="rt">
                                	<a class="btn btn-default" style="margin-top:-10px;margin-bottom:10px;" id="chooseYp">添加药品</a>
                                    <a class="btn btn-default" style="margin-top:-10px;margin-bottom:10px;" id="clear">清空内容</a>   
                                </div>                          
                            </div>
                        </div>
                    </div>
                    <!-- 患者医嘱 -->
                    <div class="r8">
                        <div class="col-sm-2 col-md-2 col-lg-2 lf left ">
                            <span>医嘱:</span>
                        </div>
                        <div class="col-sm-10 col-md-10 col-lg-10 lf right">
                            <textarea name="" id="yizhu" cols="30" rows="4" placeholder="请输入医嘱信息" class="textarea"></textarea>
                        </div>
                    </div>
                    <!-- 收货人信息 -->
                    <div class="r6">
                        <div class="col-sm-2 col-md-2 col-lg-2 lf left ">
                            <span>收货人信息:</span>
                        </div>
                        <div class="col-sm-10 col-md-10 col-lg-10 lf right">
                            <input type="text" class="consignee">
                        </div>
                    </div>
                    <!-- 价格结算 -->
                    <div class="r5">
                        <div class="col-sm-offset-2 col-sm-10 col-md-offset-2 col-md-10 col-lg-offset-2 col-lg-10 js">
                            <ul class="ul">
                                <li class="lf ypje">
                                    药品金额：
                                    <span id="ypje">0</span>
                                </li>
                                <li class="lf zlfy">
                                    治疗费用：
                                    <input type="text" class="fy" id="zlfy" value="0">元
                                </li>
                                <li class="rt">
                                    合计金额：
                                    <span>￥&nbsp;
                                        <b id="hjje">0</b>元</span>
                                </li>
                            </ul>
                        </div>
                    </div>
                    <!-- 表单提交 -->
                    <div class="bottom col-sm-offset-5 col-sm-2 col-md-offset-5 col-md-2 col-lg-offset-5 col-lg-2">
                        <a class="btn btn-success sub" style="width:100%;">提交</a>
                        <input type="hidden" name="hzId" value="${caseOrder.hzId }" class="hzId">
                        <input type="hidden" name="id" value="${caseOrder.id }" class="id">
                        <input type="hidden" name="bldCode" value="${caseOrder.bldCode }" class="bldCode">
                    </div>
                </form>
            </div>
        </div>
    </div>
    <!--固定定位的登录模态框-->
    <div class="modal fade" tabindex="-1" role="dialog" aria-hidden="true" data-backdrop="static" aria-labelledby="gridSystemModalLabel"
        id="ceshi">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="false">&times;</span>
                    </button>
                    <p class="modal-title" id="gridSystemModalLabel">常用处方选择</p>
                </div>
                <div class="modal-body">
                    <form class="form-horizontal" action="">
                        <div class="form-group">
                            <div class="col-sm-12">
                                <table class="table table-bordered table-hover table-condensed" id="table5">
                                    <tr>
                                        <td>选择</td>
                                        <td>处方名称</td>
                                        <td>选择</td>
                                        <td>处方名称</td>
                                        <td>选择</td>
                                        <td>处方名称</td>
                                        <td>选择</td>
                                        <td>处方名称</td>
                                    </tr>
                                    <tr>
                                        <td>
                                            <input type="radio" name="test" id="cs5">
                                        </td>
                                        <td><label for="cs5">白血病</label></td>
                                        <td>
                                            <input type="radio" name="test" id="cs6">
                                        </td>
                                        <td><label for="cs6">白血病</label></td>
                                        <td>
                                            <input type="radio" name="test" id="cs7">
                                        </td>
                                        <td><label for="cs7">白血病</label></td>
                                        <td>
                                            <input type="radio" name="test" id="cs8">
                                        </td>
                                        <td><label for="cs8">白血病</label></td>
                                    </tr>
                                </table>
                            </div>
                        </div>
                        <div class="modal-footer">
                            <button type="button" class="btn btn-default" data-dismiss="modal" style="padding-left: 5px;padding-right: 5px;">确定</button>
                        </div>
                    </form>
                </div>
            </div>
            <!-- /.modal-content -->
        </div>
        <!-- /.modal-dialog -->
    </div>
    <!-- /.modal -->
    --%> 
    <script type="text/javascript">
			$(function(){
			<%--	var _reg = /^\d{0,10}(.\d{1,2})?$/;
			  
				//处方单表单隐藏
				$(".main").css('display','none');
				var has = '${has}';
				
				//查询患者病历单匹配一个时，显示添加处方表单
	    		if(has==1){
	    			$(".main").show();
	    		}
	    		 
	     		//清除处方药品内容
	    		$("#clear").click(function(){
	    			$("#table4 tr:gt(0)").remove();		//清除所有添加的药品
	    			$("#ypje").text(0);					//药品价格清零
	    			//计算合计金额
	    			var zlfy = $("#zlfy").val();
	    			if(_reg.test(zlfy)){
	    				$("#hjje").text(zlfy);
	    			}else{
	    				$("#hjje").text(0);
	    			}
	    		});
	    		 
	    		//新增药品
	    		function addYp(){
	    			alert("添加药品");
	    		}
	    	
	    		
	    		//添加处方药品
	    		$("#chooseYp").click(function(){
		    			//追加药品
						top.jzts();	//显示加载进度
						 var diag = new top.Dialog();
						 diag.Drag=true;
						 diag.Title ="新增";
						 diag.URL = '<%=basePath%>cfOrder/chooseYp.do';
				 		 diag.Width = 1000;
						 diag.Height = 800; 
						 diag.CancelEvent = function(){ //关闭事件
						 	if(window.top.selectYp=="has"){
							 		console.info(window.top.ypId);
							 		console.info(window.top.ypCode);
							 		console.info(window.top.ypName);
							 		console.info(window.top.ypUnit);
							 		console.info(window.top.ypUsage);
							 		console.info(window.top.price);
							 		console.info(window.top.kcTotal);
							 		console.info(window.top.number);
							 		
			    			 
			    					//序号
			    					var xuhao = $("#table4 tr:last td:first").text();
			    					console.info("xuhao--------"+xuhao);
			    					if(xuhao!="序号"){
			    						xuhao = Number(xuhao) + Number(1);
			    					}else{
			    						xuhao = 1;
			    					}
					    			var zj = (Number(window.top.price)*Number(window.top.number)).toFixed(2);	//一个药品总价
					    			
					    		 	$("#table4").append("<tr>"+
					    									"<td>"+xuhao+"</td>"+
					    									"<td>"+window.top.ypCode+"</td>"+
					    									"<td>"+window.top.ypName+"</td>"+
					    									"<td>"+window.top.ypUnit+"</td>"+
					    									"<td>"+window.top.ypUsage+"</td>"+
					    									"<td>"+window.top.price+"</td>"+			//单价
					    									"<td>"+window.top.number+"</td>"+			//用量
					    									"<td>"+zj+"</td>"+
					    									"<input type='hidden' value='"+window.top.ypId+"' class='ypId'>"+
				                                    	"</tr>"); 
				                    //计算药品总价
					    			var ypje = $("#ypje").text();	//获取药品金额
					    			var hjje = $("#hjje").text();	//获取合计金额
					    			ypje =Number( (Number(ypje) + Number(zj) ).toFixed(2) );		//药品金额 = 原药品金额 + 一个药品的总价
					    			hjje =Number( (Number(hjje) + Number(zj) ).toFixed(2));			//合计金额 = 原合计金额 +一个药品的总价 
					    			$("#ypje").text(ypje);		//修改药品金额
					    			$("#hjje").text(hjje);		//修改合计金额
								}
						 //	alert(window.top.selectYp.ypmc);
							 if(diag.innerFrame.contentWindow.document.getElementById('userForm').style.display == 'none'){
								 if('${page.currentPage}' == '0'){
									 top.jzts();
									 setTimeout("self.location=self.location",100);
								 }else{
									 nextPage(${page.currentPage});
								 }
							}
							diag.close();
						 };
						 diag.show();
	    		});
	    		
	    		//治疗费用失去焦点时，验证输入的内容
	    		$("#zlfy").blur(function(){
	    			var zlfy = $("#zlfy").val();
	    			if(_reg.test(zlfy)){
	    				var ypje = $("#ypje").text();
	    				var hjje =  Number((Number(ypje) + Number(zlfy)).toFixed(2));
	    				 $("#hjje").text(hjje);
	    			}else{
	    				$("#zlfy").val("0");
	    				alert("格式不正确");
	    			}
	    		});
	    		
	    		//表单提交
	    		$(".sub").click(function(){
	    			//获取处方中的每一药品，做添加
	    			var trList = $("#table4 tr:eq(0)").nextAll();		//获取药品tr集合
	    			var arrayList = new Array(trList.length);
	    			 for(var i = 0 ; i<trList.length ; i++){
	    				var child = $(trList[i]).children();			//获取药品tr下的集合
	    			 	var yp = new Array(4);
	    				//获取单价、用量、总价、药品id
	    				for(var j = 5 ,x=0; j<child.length-1; j++,x++){
	    					yp[x] = $(child[j]).text();
	    				}
	    				yp[3] = $(child[child.length-1]).val();
	    				arrayList[i] = yp ;
	    			} 
	    			console.info(arrayList);
	    			
	    			//医嘱、药品金额、治疗费用、合计金额、患者ID、病历单id
	    			var yizhu = $("#yizhu").text();
	    			var ypje = $("#ypje").text();
	    			var zlfy = $("#zlfy").val();
	    			var hjje = $("#hjje").text();
	    			var hzid = $(".hzId").val();
	    			var caseid = $(".id").val();
	    			var bldId = $(".bldId").val();
	    			$.ajax({
	    				type: "POST",
						url: "<%=basePath%>cfOrder/save.do",
				    	data: {
				    			"hzId":hzid,
				    			"caseId":caseid,
				    			"bldCode":bldId,
				    			"yiZhu":yizhu,
				    			"ypje":ypje,
				    			"zlfy":zlfy,
				    			"hjje":hjje,
				    			"ypList":JSON.stringify(arrayList)
				    		},
						dataType:'json',
						//beforeSend: validateData,
						cache: false,
						success: function(data){
							if(data.msg=="success"){
								window.location.reload(true);
							}                  
						 }
	    			});
	    		
	    		});
	    		
			});
		 --%>	
		//列表中选中一个后，列表隐藏，添加病历框展示，并赋值信息
    	function toAdd(hzId,id,name,sex,age,phone,xbs,zd){
    		$("#more").hide();
    		$(".main").show();
    		$(".name").val(name);	//姓名
    		$("#sex").text(sex);;	//性别
    		$(".age").val(age);		//年龄
    		$(".phone").val(phone);	//电话
    		$(".xbs").val(xbs);		//现病史
    		$(".zd").val(zd);		//诊断
    		$(".hzId").val(hzId);	//患者ID
    		$(".id").val(id);		//病历单id
    	};
   <%--  	
    	//加载常用处方
    	function load(){
    		$.ajax({
    			type: "POST",
				url: "<%=basePath%>cycf/list.do",
		    	data: {hzId:patientId},
				dataType:'json',
				//beforeSend: validateData,
				cache: false,
				success: function(data){
					 if(data.msg=="success"){
					 	for ( var int = 0; int < data.cycfList.length; int++) {
					 		if(int%3==0){
								$("#table5").append("<tr></tr>");
					 		}
					 		 $("#table5 tr").last().append(
					 					"<td>"+
					 						"<input type='radio' name='test' id='cs" + (int+1)+"'>"+
                                        "</td>"+
                                        "<td><label for='cs" + (int+1) + "'>" +data.cycfList[int].cycfName+"</label></td>");
						 
						}
					 }else{
					 	alert(data.msg);
					 }
				 }
    		});
    	}; --%>
	</script> 
</body>

</html>
